
#include "WProgram.h"
#include "MotorDriver.h"


/* MotorDriver
	Assigns default pins, and then calls init.
*/
MotorDriver::MotorDriver() : mMotorPin1(DEFAULT_MOTOR_PIN_1), mMotorPin2(DEFAULT_MOTOR_PIN_2) {
	init();
}

/* MotorDriver
	Assigns motor pins based on inputs, then calls init.

	input:
		motorPin1:
			First pin for the motor
		motorPin2:
			Second pin for the motor
*/
MotorDriver::MotorDriver(int motorPin1, int motorPin2) : mMotorPin1(motorPin1), mMotorPin2(motorPin2) {
	init();
}

/* init
	Sets up the motor for first time use. Sets both pins as output.
*/
void MotorDriver::init() {
	pinMode(mMotorPin1, OUTPUT);
	pinMode(mMotorPin2, OUTPUT);
}

/* rotateForward:
    Rotates the motor in the forward direction for in definite amount of time. The speed of rotation is depending on speedOfRotate.
    
    input:
      motorSpeed: 
        Speed of the motor. Value between 0 (not moving) and 255 (Full speed).
    
*/
void MotorDriver::rotateForward(int motorSpeed) {
	analogWrite(mMotorPin1, motorSpeed);
	digitalWrite(mMotorPin2, LOW);
}

/* rotateReverse:
    Rotates the motor in the reverse direction for in definite amount of time. The speed of rotation is depending on speedOfRotate.
    
    input:
      motorSpeed: 
        Speed of the motor. Value between 0 (not moving) and 255 (Full speed).
    
*/
void MotorDriver::rotateReverse(int motorSpeed) {
	analogWrite(mMotorPin2, motorSpeed);
	digitalWrite(mMotorPin1, LOW);
}

/* rotateForwardFull:
    Rotates the motor in the forward direction at full speed.
*/
void MotorDriver::rotateForwardFull() {
	digitalWrite(mMotorPin1, HIGH);
	digitalWrite(mMotorPin2, LOW);
}

/* rotateReverseFull:
    Rotates the motor in the reverse direction at full speed.   
*/
void MotorDriver::rotateReverseFull() {
	digitalWrite(mMotorPin2, HIGH);
	digitalWrite(mMotorPin1, LOW);
}

/* stopMotor:
    Stops the motor from any rotation
*/
void MotorDriver::stopMotor() {
	digitalWrite(mMotorPin1, LOW);
	digitalWrite(mMotorPin2, LOW);
}

	
